/**
 * create by ck on 2016/3/18.
 */

$(function () {
    obj.init();
});
var obj = new JsFun();
function JsFun() {
    return {
        dataGrid: null,
        form: null,
        flow: null,
        dom: {

        },
        init: function () {
            this.form = new xhForm($('#xh_form'));
            this.listener();
            this.date();
        },
        date:function () {
            laydate.render({
                elem: '#tStartTime'
            });
            laydate.render({
                elem: '#tEndTime'
            });
        },
        listener: function () {
            var $this = this;
            $('#bt_form_back').click(function() {
                window.top.xhTop.closeModal();
            });
            $('#bt_form_add').click(function () {
                var sTitle = $('#sTitle', window.self.document).val();

                if(!sTitle){
                    window.top.xhTop.showMessage({title: '标题不能为空！', type: 'error'});
                    return false;
                }
                var tStartTime = $('#tStartTime', window.self.document).val();
                if(!tStartTime){
                    window.top.xhTop.showMessage({title: '开始时间不能为空！', type: 'error'});
                    return false;
                }
                var tEndTime = $('#tEndTime', window.self.document).val();
                if(tEndTime && tStartTime > tEndTime){
                    window.top.xhTop.showMessage({title: '结束时间大于开始时间！', type: 'error'});
                    return false;
                }
                // if( $('input:radio[name="iStatus"]:checked', window.self.document)){
                //     var iStatus = $('input:radio[name="iStatus"]:checked', window.self.document).val();
                //     if(iStatus===undefined){
                //         window.top.xhTop.showMessage({title: '请选择状态！', type: 'error'});
                //         window.top.xhTop.closeModal();
                //         return false;
                //     }
                // }
                var url = window.location.href;
                url = url.replace(/^http:\/\/[^/]+/, "");
                $this.form.submit(url, {}, function (data) {
                    if (xhExtra.checkError(data)) return false;
                    window.top.xhTop.getActiveFrame().getSchedule();
                    window.top.xhTop.closeModal();
                });
            })
        },
        funObj: function () {
            return {

            }
        }
    }
}